<?php
namespace app\tour\model;

use think\Model;
use think\Db;
use think\Session;

class Admin extends Model
{

    /**
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getAdminList(){
        $where['is_del'] = array('eq',0);
        $adminList = Db::name('tour_admin')->alias('t1')->field('t1.*,t3.title as role_name,t3.id as role_id
')->join('tour_auth_group_access t2','t1.t_admin_id = t2.uid','left')
            ->join('tour_auth_group t3','t2.group_id = t3.id','left')
            ->where($where)->where('t1.tour_id',Session::get('tour_id'))->order('t1.t_admin_id','desc')->select();
       // $tour_id = Session::get('tour_id');

       // $adminList = Db::name('tour_admin')->where("tour_id",$tour_id)->where('is_del',0)->select();

        return $adminList;

    }

    /**
     * @param $data
     * @return int|string
     */
    static function addAdmin($data){

        return Db::name('tour_admin')->insertGetId($data);

    }


    /**
     * @param $tel
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getAdminByTel($tel){

        $res = Db::name('tour_admin')->where("t_admin_tel",$tel)->find();

        return $res;

    }

    static function editAdmin($t_admin_id,$updateData){

        return Db::name('tour_admin')->where('t_admin_id',$t_admin_id)->update($updateData);

    }

    static function delAdmin($t_admin_id,$updateData){

        return Db::name('tour_admin')->where('t_admin_id',$t_admin_id)->delete();

    }

}